var util = require('../../../utils/util.js');
const app = getApp()

Page({
  data: {
    isShow: true,
    nowMoney: '',
    payFaceToFace: [],
    cardCount: 0,
    couponCount: 0,
    chongzhi: 2
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var now = options.now;
    that.setData({
      chongzhi: app.globalData.rechargeStatus,
      nowMoney: now
    })
    that.getMy()
  },
  
  // 下拉刷新
  onPullDownRefresh: function () {
    // 显示顶部刷新图标
    wx.showNavigationBarLoading();
    this.getMy();
    // 隐藏导航栏加载框
    wx.hideNavigationBarLoading();
    // 停止下拉动作
    wx.stopPullDownRefresh();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  toggle() {
    this.setData({
      isShow: !this.data.isShow
    })
  },
  records() {
    wx.navigateTo({
      url: '/pages/ucenter/records/records',
    })
  },
  getMy() {
    var that = this;
    util.request('coupon/userCount').then(function(res) {
      if (res.code === 0) {
        that.setData({
          couponCount: res.data || 0
        })
      }
    });
    util.request('user/payFaceToFaceList').then(function(res) {
      if (res.code === 0) {
        that.setData({
          payFaceToFace: res.data
        })
      }
    });
    util.request('user/getBankCard').then(function(res) {
      if (res.code === 0) {
        that.setData({
          cardCount: res.data.length || 0
        })
      }
    });
    util.request('coupon/userCount').then(function(res) {
      if (res.code === 0) {
        that.setData({
          couponCount: res.data || 0
        })
      }
    });
  },
  goPayment: function() {
    wx.navigateTo({
      url: '/pages/ucenter/chongzhi/chongzhi',
    })
  },
  coupon: function() {
    wx.navigateTo({
      url: '/pages/ucenter/coupon/coupon',
    })
  },
  bankCard: function() {
    wx.navigateTo({
      url: '/pages/ucenter/bankCard/bankCard',
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})
